<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<#include "/view/head.html"/>
<script type="text/javascript">
<#if errors??>
	var msg = '';
	<#list errors as error>
	msg = msg + '${error}\n';
	</#list>
	alert(msg);
</#if>

function validate() {
	$("#info").text("");
	var code = $('#code').val();
	if(!code){
		$("#info").text("请输入电子票编号");
		return;
	}
	var count = $('#count').val();
	if(!count){
		$("#info").text("请输入验证张数");
		return;
	}
	$.post('${base}/ticket/validate', {'code':code, 'count':count}, function(data){
		if(data.indexOf("<html")>0){
			alert("登陆失效，请重新登陆！");
			top.location.href='${base}/login';
			return;
		}
		data=eval('('+data+')');
		if(data.result){
			var msg = '验证张数：'+data.count+'验证时间：'+data.time;
			$("#info").text('#'+code+' 消费成功！' + msg);
			alert('消费成功！');
			$("#jvForm").reset();
		} else {
			$("#info").text('#'+code+' '+data.message);
		}
	});
}
function search() {
	$("#info").text("");
	var code = $('#code').val();
	if(!code){
		$("#info").text("请输入电子票编号");
		return;
	}
	$.post('${base}/ticket/query', {'code':code}, function(data){
		if(data.indexOf("<html")>0){
			alert("登陆失效，请重新登陆！");
			top.location.href='${base}/login';
			return;
		}
		data=eval('('+data+')');
		if(data.result){
			var msg = '可验证'+data.total+'次，已验证'+data.count+'次';
			if(data.time) msg = msg + "，验证时间 "+data.time;
			$("#info").text('#'+code+' '+msg);
		} else {
			$("#info").text('#'+code+' 有效：'+data.message);
		}
	});
}

</script>
</head>
<body>
<#include "/common/image_upload.html"/>
<div class="body-box">
<div class="rhead">
	<div class="rpos">电子票验证</div>
	<div class="clear"></div>
</div>
<div style="display:block;height:45px;color:red">
<h2 id="info"></h2>
</div>
<@p.form id="jvForm" labelWidth="12">
<@p.text width="50" colspan="2" label="电子票编号" id="code" name="code" required="true" class="required" size="70" maxlength="100"/><@p.tr/>
<@p.text width="50" colspan="2" label="验证张数" id="count" name="count" value="1" required="true" class="required digits" size="70" maxlength="100"/><@p.tr/>
<@p.td colspan="2">
<input type="button" value="查询" onclick="search();"/>&nbsp;
<input type="button" value="验证" onclick="validate();"/>&nbsp;
</@p.td>
</@p.form>

</div>
<#include "/common/alert_message.html"/>
</body>
</html>
